*********************************************************************************
* Figure 5																		*
*********************************************************************************

* Project: 	Stability of national identity
* Authors: 	Matthias Mader
* Date:		Feb 2023

*********************************************************************************
*******************************************************************************


*** Setup

	set more off            					// Disable partitioned output
	set dp period								// Use comma instead of dot for decimals
	set linesize 80         					// Line size limit to make output more readable
	macro drop _all         					// clear all macros
	set scheme plotplainblind					// set graph scheme
	graph set window fontface "Times New Roman" // set font 


*** Open data set

use "DATA_clean.dta", clear


*** Reduce to balanced panel

	drop if ethnic21_cat1 == . | ///
	ethnic32_cat1 == . | ///
	ethnic43_cat1 == . | ///
	ethnic41_cat1 == . | ///
	civic21_cat1 ==. | ///
	civic32_cat1 == . | ///
	civic43_cat1 == . | ///
	civic41_cat1 == . | ///
	id21_cat1 == . | ///
	id32_cat1 == . | ///
	id43_cat1 == . | ///
	id41_cat1 == . | ///
	rwa21_cat1 == . | ///
	rwa32_cat1 == . | ///
	rwa43_cat1 == . | ///
	rwa41_cat1 == .


*** Figure 5: Effects on immigration attitude and far-right party support

*** DV: Immigration attitude
*** Predicted DV scores plot

	sum ethnic_abs [aw = wei5_mz], det // "Low stability" = .3; "High stability" = 3.7

	reg immi c.ethnic4r##c.ethnic_abs civic4r id4r [pw = wei5_mz]
	margins, dydx(ethnic4r) at(ethnic_abs=(.3 3.7))
	margins, at(ethnic4r=(0(.02)1) ethnic_abs=(.3 3.7))
	marginsplot,  ///
			name(g1, replace) ///
			recast(scatter) ///
			plotopts(mcolor(none))  ///
			ciopts(recast(rbar) barwidth(0.01)) ///
			xtitle("Ethnic dimension", size(large)) xscale(range(0 1)) xlabel(0 (0.2) 1, labsize(large)) ///	
			ytitle("Immigration attitude", size(large)) yscale(range(-.01 1)) ylabel(0 (.2) 1, labsize(large)) ///	
			text(.83 0 "High stability", color(gs0) size(large)	place(right)) ///
			text(.76 0 "b = -0.50 CI95[-0.55, -0.45]", color(gs0) size(large)	place(right)) ///
			text(.30 0 "Low stability", color(gs8) size(large)	place(right)) ///
			text(.23 0 "b = -0.28 CI95[-0.33, -0.22]", color(gs8) size(large)	place(right)) ///
			title("") ///
			legend(off)


	sum civic_abs [aw = wei5_mz], det // "Low stability" = .3; "High stability" = 2.7

	reg immi c.civic4r##c.civic_abs ethnic4r id4r [pw = wei5_mz]
	margins, dydx(civic4r) at(civic_abs=(0.3 2.7))
	margins, at(civic4r=(0(.02)1) civic_abs=(0.3 2.7))
	marginsplot,  ///
			name(g2, replace) ///
			recast(scatter) ///
			plotopts(mcolor(none))  ///
			ciopts(recast(rbar) barwidth(0.01)) ///
			xtitle("Civic dimension", size(large)) xscale(range(0 1)) xlabel(0 (0.2) 1, labsize(large)) ///	
			ytitle("Immigration attitude", size(large)) yscale(range(-.01 1)) ylabel(0 (.2) 1, labsize(large)) ///	
			title("") ///
			text(.53 1 "b = .40 CI95[.33, .47]", color(gs0) size(large)	place(left)) ///
			text(.18 1 "b = .28 CI95[.22, .34]", color(gs8) size(large)	place(left)) ///
			legend(off)



*** DV: AfD support
*** Predicted DV scores plot

reg afdscalo c.ethnic4r##c.ethnic_abs  civic4r id4r
margins, dydx(ethnic4r) at(ethnic_abs=(.3 3.7))
margins, at(ethnic4r=(0(.02)1) ethnic_abs=(.3 3.7))
marginsplot,  ///
			name(g3, replace) ///
			recast(scatter) ///
			plotopts(mcolor(none))  ///
			ciopts(recast(rbar) barwidth(0.01)) ///
			xtitle("Ethnic dimension", size(large)) xscale(range(0 1)) xlabel(0 (0.2) 1, labsize(large)) ///	
			ytitle("AfD support", size(large)) yscale(range(0 1)) ylabel(0 (.2) 1, labsize(large)) ///				
			title("") ///
			text(.42 1 "b = .26 CI95[.22, .31]", color(gs0) size(large)	place(left)) ///
			text(.07 1 "b = .11 CI95[.07, .16]", color(gs8) size(large)	place(left)) ///
			legend(off)
 
reg afdscalo c.civic4r##c.civic_abs ethnic4r id4r
margins, dydx(civic4r) at(civic_abs=(.3 2.7))
margins, at(civic4r=(0(.02)1) civic_abs=(.3 2.7))
marginsplot,  ///
			name(g4, replace) ///
			recast(scatter) ///
			plotopts(mcolor(none))  ///
			ciopts(recast(rbar) barwidth(0.01)) ///
			xtitle("Civic dimension", size(large)) xscale(range(0 1)) xlabel(0 (0.2) 1, labsize(large)) ///	
			ytitle("AfD support", size(large)) yscale(range(0 1)) ylabel(0 (.2) 1, labsize(large)) ///	
			title("") ///
			text(.60 0 "b = -.39 CI95[-.46, -.33]", color(gs0) size(large)	place(right)) ///
			text(.20 0 "b = -.29 CI95[-.35, -.24]", color(gs8) size(large)	place(right)) ///
			legend(off)

